package com.smartshopping.iu.test;

import com.smartshopping.iu.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import android.app.Instrumentation.ActivityMonitor;
import android.test.ActivityInstrumentationTestCase2;
import android.widget.TextView;
import com.jayway.android.robotium.solo.Solo;

import com.smartshopping.iu.R;
public class Smart extends ActivityInstrumentationTestCase2<IndexActivity> {
	private   Solo   solo ;
	public Smart() {
		super("com.smartshopping.iu",IndexActivity.class);
	}

	protected void setUp() throws Exception {
		super.setUp();
		solo = new Solo(getInstrumentation(),getActivity());
	}
	
public void test1SearchMarket () throws Exception
{
	

	android.view.View button = solo.getView(R.id.index_button_imageview1);
	solo.sleep(2000);
	solo.clickOnView(button);
	solo.sleep(2000);
	solo.assertCurrentActivity("Market Choose", MarketActivity.class);
	solo.sleep(2000);
	solo.scrollToBottom();
	solo.sleep(2000);
	solo.enterText(0, "CoopMart");
	solo.sleep(2000);
	boolean actual = solo.searchText("Co.opMart");
	assertNotSame(true, actual); //Search if not have in list
	solo.sleep(2000);
	solo.clearEditText(0);
	solo.sleep(2000);
	solo.enterText(0, "Co.op");
	solo.sleep(2000);
	solo.clearEditText(0);
	solo.sleep(2000);
	solo.enterText(0, "Satra");
	android.view.View button1 = solo.getView(R.id.market_imageButton_coop);
	solo.clickOnView(button1);
	solo.sleep(2000);
	boolean actual2 = solo.searchText("FamilyMart");
	assertNotSame(true, actual2); ////Search if not have in list
	solo.sleep(2000);
	solo.goBack();
	solo.sleep(2000);
	android.view.View button3 = solo.getView(R.id.market_imageButton_coop);
	solo.clickOnView(button3);
	assertSame(true, solo.searchText("Big C"));
	solo.sleep(2000);
	solo.clickLongOnText("Big C");
	solo.sleep(2000);
	solo.searchText("Big C An Lạc");
	solo.sleep(2000);
	solo.clickOnText("Big C Hoàng Văn Thụ");
	solo.assertCurrentActivity("List Choose", ListGoodActivity.class);
	android.view.View button2 = solo.getView(R.id.good_imageButton_type);
	solo.clickOnView(button2);
	solo.sleep(2000);
	solo.clickLongOnText("Bánh");
	solo.sleep(2000);
	solo.enterText(0, "Bánh");
	solo.sleep(2000);
	solo.clearEditText(0);
	solo.sleep(2000);
	solo.enterText(0, "Kẹo");
	solo.sleep(2000);
	solo.clickLongInList(0);
	solo.sleep(2000);
	solo.assertCurrentActivity("Item Des", GoodDetailActivity.class);
	
}



public  void test2Billnoitem ()  throws Exception 
{	
	int j = 0;
	int i = 0;
	int current=0;
	int before=0;
	android.view.View button = solo.getView(R.id.index_button_imageview1);
	solo.clickOnView(button);
	solo.assertCurrentActivity("Market Choose", MarketActivity.class);
	solo.searchText("Big C");
	solo.clickOnText("Big C Hoàng Văn Thụ");
	solo.clickLongInList(0);	
	solo.assertCurrentActivity("CheckBuy", GoodDetailActivity.class);
	while (i < 11) //check add button
	{
	android.view.View buyadd = solo.getView(R.id.good_detail_imageButton_add);
	solo.clickOnView(buyadd);
    current++;
    i++;
	}
	while (j < 3) // check sub button
	{
   
	android.view.View buysub = solo.getView(R.id.good_detail_imageButton_sub);
	solo.clickOnView(buysub);
	j++;
	--current;
	}
	before = current;
	assertTrue("Check amount", solo.searchText("Mua hàng: " + before));
	solo.sleep(5000);
	android.view.View notbuy = solo.getView(R.id.good_detail_imageButton_notbuy);
	solo.clickOnView(notbuy); //Test notbuy return amount 0
	assertTrue("Check notbuy", solo.searchText("Mua hàng: " + "0"));
	solo.sleep(2000);
	android.view.View finish = solo.getView(R.id.good_detail_imageButton_finish);
	solo.clickOnView(finish); // Check bill with have nothing item in list.
	solo.assertCurrentActivity("Check Finish", ListGoodActivity.class);
	solo.sleep(2000);
	android.view.View Bill = solo.getView(R.id.good_imageButton_bill);
	solo.clickOnView(Bill);
	solo.enterText(0, "Test note");
	android.view.View save = solo.getView(R.id.bill_save_bill);
	solo.clickOnView(save);
   boolean dialog = solo.waitForDialogToOpen(5);
    assertFalse(dialog); //Test dialog button
    solo.sleep(5000);
    solo.goBackToActivity("IndexActivity");
    android.view.View note = solo.getView(R.id.index_button_imageview4);
	solo.clickOnView(note);
	solo.sleep(10000);
}	
public void test3Billwithitem() throws Exception 
{
	int j = 0;
	int i = 0;
	int k = 0;
	int h = 0;
	int current=0;
	int price = 29800;
	android.view.View button = solo.getView(R.id.index_button_imageview1);
	solo.clickOnView(button);
	solo.assertCurrentActivity("Market Choose", MarketActivity.class);
	solo.searchText("Big C An Lạc");
	solo.clickOnText("Big C Hoàng Văn Thụ");
	solo.clickOnText("Bàn chải đánh răng Colgate 360 Sensitive");	
	solo.assertCurrentActivity("CheckBuy", GoodDetailActivity.class);
	while (i < 11) //check add button
	{
	android.view.View buyadd = solo.getView(R.id.good_detail_imageButton_add);
	solo.clickOnView(buyadd);
    current++;
    i++;
	}
	while (j < 3) // check sub button
	{
   
	android.view.View buysub = solo.getView(R.id.good_detail_imageButton_sub);
	solo.clickOnView(buysub);
	j++;
	--current;
	}
	android.view.View finish = solo.getView(R.id.good_detail_imageButton_finish);
	solo.clickOnView(finish); 
	solo.assertCurrentActivity("Check Finish", ListGoodActivity.class);
	solo.clickOnText("Bàn chải đánh răng Colgate 360 Sensitive");
	assertTrue("Check notremove", solo.searchText("Mua hàng: " + current)); //Check amount still save
	solo.goBack();
	android.view.View Bill = solo.getView(R.id.good_imageButton_bill);
	solo.clickOnView(Bill);
	solo.enterText(0, "Test note ");
	solo.sleep(2000);
	solo.clickOnImage(2);
	solo.sleep(2000);
	current = 0;
	while (k < 5) //check add button
	{
		solo.clickOnImage(1);
    current++;
    k++;
	}
	while (h < 4) // check sub button
	{
   
		solo.clickOnImage(0);
	h++;
	--current;
	}
	solo.sleep(2000);
	int total1 = (price*current);
	assertTrue("Check item",solo.searchText("Bàn chải đánh răng Colgate 360 Sensitive")); 
	assertTrue("Check price",solo.searchText("Total price : " + total1));
	assertTrue("CheckAmount",solo.searchText("SL : " + current));
	android.view.View save = solo.getView(R.id.bill_save_bill);
	solo.clickOnView(save);
	solo.sleep(2000);
	solo.clickOnButton(0);
	DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
	Date date = new Date();
	String dateTest = dateFormat.format(date);
	solo.assertCurrentActivity("Check bill",BillActivity.class);
	solo.goBackToActivity("IndexActivity");
	android.view.View note = solo.getView(R.id.index_button_imageview4);
	solo.clickOnView(note);
	solo.sleep(5000);
	assertTrue("Check note",solo.searchText(dateTest));
	solo.clickLongOnText(dateTest);
	//assertTrue("Check note2",solo.searchText(current + total)); //Check note information
	solo.sleep(5000);
	solo.goBackToActivity("IndexActivity");
	android.view.View about = solo.getView(R.id.index_button_imageview6);
	solo.clickOnView(about);
	solo.sleep(10000);
}


@Override
	public void tearDown() throws Exception {
	     solo.finishOpenedActivities();
	}

}
